//
//  HomeVC.swift
//  Drop
//
//  Created by zhuxuhong on 2018/3/17.
//  Copyright © 2018年 zhuxuhong. All rights reserved.
//

import UIKit

class HomeVC: UIPageViewController {

    let pageDataSource = HomePageDataSource()
    
    override func viewDidLoad() {
        super.viewDidLoad()
		
        pageDataSource.pageData = ["1", "2"]
        
        if let startViewController = pageDataSource.viewControllerAtIndex(0, storyboard: storyboard!){
            setViewControllers([startViewController], direction: .forward, animated: false, completion: nil)
        }
        
        dataSource = pageDataSource
    }

    @IBAction func unwindHomeVC(_ sender: UIStoryboardSegue) {
		if let vc = sender.source as? TextComposingVC {
            let drop = Drop()
            drop.content.text = vc.textView.text
			if let firsPage = viewControllers?.first as? DropListVC{
				firsPage.drops.insert(drop, at: 0)
				firsPage.tableView.insertRows(at: [.zero], with: .automatic)
				firsPage.tableView.scrollToRow(at: .zero, at: .top, animated: true)
			}
		}
    }
}
